package com.ynwt.domain;

import com.ynwt.enums.UserSex;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by huangying on 2017/4/26.
 */
@Entity
@Table(indexes = {
        @Index(name = "pk_openid", columnList = "openid", unique = true),
        @Index(name = "uk_unionid", columnList = "unionid", unique = true)})
public class User {

    @Id
    @Column(length = 50)
    private String openid; //用户的标识，对当前公众号唯一

//    @Column(insertable = false, updatable = false, unique = true, nullable = false)
//    private Long id; //参数二维码参数

    @Column
    private String headImgUrl; //用户头像，最后一个数值代表正方形头像大小（有0、46、64、96、132数值可选，0代表640*640正方形头像），用户没有头像时该项为空。若用户更换头像，原有头像URL将失效。

    @Column(length = 1)
    private Integer subscribe; //用户是否订阅该公众号标识，值为0时，代表此用户没有关注该公众号，拉取不到其余信息。

    @Column(length = 200)
    private String nickname; //用户的昵称

    @Column
    @Enumerated
    private UserSex sex; //用户性别

    @Column
    private Long subscribeTime; //用户关注时间，为时间戳。如果用户曾多次关注，则取最后关注时间

    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private Date regTime; //用户注册时间（成为环球小伙伴的时间）

    @Column(length = 50)
    private String unionid; //只有在用户将公众号绑定到微信开放平台帐号后，才会出现该字段。详见：获取用户个人信息（UnionID机制）

    @Column
    private String qrcodeUrl; //参数二维码存放路径

    @Column(length = 50)
    private String city; // 用户所在城市

    @Column(length = 50)
    private String country; // 用户所在国家

    @Column(length = 50)
    private String province; // 用户所在省份

    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private Date qrcodeRefreshTime; //参数二维码上一次刷新时间

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<UserEvent> events = new HashSet<>();

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<UserEventLock> locks = new HashSet<>();

    public User() {
    }

    public User(String openid) {
        this.openid = openid;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

//    public Long getId() {
//        return id;
//    }
//
//    public void setId(Long id) {
//        this.id = id;
//    }

    public String getHeadImgUrl() {
        return headImgUrl;
    }

    public void setHeadImgUrl(String headImgUrl) {
        this.headImgUrl = headImgUrl;
    }

    public Integer getSubscribe() {
        return subscribe;
    }

    public void setSubscribe(Integer subscribe) {
        this.subscribe = subscribe;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public UserSex getSex() {
        return sex;
    }

    public void setSex(UserSex sex) {
        this.sex = sex;
    }

    public Long getSubscribeTime() {
        return subscribeTime;
    }

    public void setSubscribeTime(Long subscribeTime) {
        this.subscribeTime = subscribeTime;
    }

    public Date getRegTime() {
        return regTime;
    }

    public void setRegTime(Date regTime) {
        this.regTime = regTime;
    }

    public String getUnionid() {
        return unionid;
    }

    public void setUnionid(String unionid) {
        this.unionid = unionid;
    }

    public String getQrcodeUrl() {
        return qrcodeUrl;
    }

    public void setQrcodeUrl(String qrcodeUrl) {
        this.qrcodeUrl = qrcodeUrl;
    }

    public Date getQrcodeRefreshTime() {
        return qrcodeRefreshTime;
    }

    public void setQrcodeRefreshTime(Date qrcodeRefreshTime) {
        this.qrcodeRefreshTime = qrcodeRefreshTime;
    }

    public Set<UserEvent> getEvents() {
        return events;
    }

    public void setEvents(Set<UserEvent> events) {
        this.events = events;
    }

    public Set<UserEventLock> getLocks() {
        return locks;
    }

    public void setLocks(Set<UserEventLock> locks) {
        this.locks = locks;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }
}
